local skel = fk.CreateSkill {
  name = "lb__junlin",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable {
  ["lb__junlin"] = "君临",
  --[":lb__junlin"] = "<b>锁定技</b>，当你使用牌后，若花色或类型与首张「<b>断海</b>」牌相同，你摸一张牌；若均不同，弃置首张「<b>断海</b>」牌并对一名角色造成1点伤害，若其不为当前回合角色，你失去1点体力并将手牌数弃至体力上限，然后结束当前回合。",
  --9.16
  --[":lb__junlin"] = "<b>锁定技</b>，当你使用牌后，若类型与首张「<b>断海</b>」牌相同，你摸一张牌；若不同，弃置首张「<b>断海</b>」牌并对一名角色造成1点伤害，若其不为当前回合角色，你失去1点体力并结束当前回合。",
  --9.18
  --[":lb__junlin"] = "<b>锁定技</b>，当你使用牌后，若类型与首张「<b>断海</b>」牌相同，你摸一张牌或弃置首张「<b>断海</b>」牌；若不同，你获得首张「<b>断海</b>」牌并对一名角色造成1点伤害，若其不为当前回合角色，你失去1点体力并结束当前回合。",
  --9.21
  --[":lb__junlin"] = "<b>锁定技</b>，当你使用牌后，若类型与首张「<b>断海</b>」牌相同，你摸一张牌或弃置首张「<b>断海</b>」牌；若不同，你失去1点体力，然后获得首张「<b>断海</b>」牌并对一名角色造成1点伤害，若其不为当前回合角色，结束当前回合。",
  --11.6
  [":lb__junlin"] = "<b>锁定技</b>，当你使用牌后，若你的体力值大于1且此牌类型与首张「<b>断海</b>」牌：<br>"..
  "相同，你摸一张牌或弃置首张「<b>断海</b>」牌；<br>"..
  "不同，你失去1点体力，然后获得首张「<b>断海</b>」牌并对一名角色造成1点伤害，若其不为当前回合角色，结束当前回合。",


  ["#lb__junlin"] = "君临：请选择一名角色，你对其造成1点伤害，若其不为当前回合角色，结束当前回合",
  ["#lb__junlin_darw"] = "君临：你可以弃置「<b>断海</b>」牌 %arg ，或取消后摸一张牌",

  ["$lb__junlin1"] = "不必畏惧。",
  ["$lb__junlin2"] = "尚未了结。",
}

skel:addEffect(fk.CardUseFinished, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and #player:getPile("$lb__duanhai") > 0 and player.hp > 1
  end,
  on_use = function(self, event, target, player, data)
    local ids = player:getPile("$lb__duanhai")
    if #ids > 0 then
      local room = player.room
      local card = Fk:getCardById(ids[1])
      --if data.card.type == card.type or data.card.suit == card.suit then
      if data.card.type == card.type then
        if room:askToSkillInvoke(player, {skill_name = skel.name, prompt = "#lb__junlin_darw:::"..card:toLogString()}) then
          room:moveCardTo(card, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, skel.name, "$lb__duanhai", true, player)
        else
          player:drawCards(1, skel.name)
        end
      else
        room:loseHp(player, 1, skel.name)
        if player.dead then return end
        room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonJustMove, skel.name, "$lb__duanhai", true, player)
        local tos = room:askToChoosePlayers(player, {
          targets = room:getAlivePlayers(),
          min_num = 1,
          max_num = 1,
          skill_name = skel.name,
          cancelable = false,
          prompt = "#lb__junlin",
        })
        if #tos > 0 then
          local current = room:getCurrent()
          local lose = current and current.id == tos[1].id
          room:damage {
            from = player,
            to = tos[1],
            skillName = skel.name,
            damage = 1,
          }
          if not lose then
            --room:loseHp(player, 1, skel.name)
            --[[
            if player:getHandcardNum() > player.maxHp and not player.dead then
              room:askToDiscard(player, {
                min_num = player:getHandcardNum() - player.maxHp,
                max_num = player:getHandcardNum() - player.maxHp,
                include_equip = false,
                skill_name = skel.name,
                cancelable = false,
              })
            end
            --]]
            room:endTurn()
          end
        end
      end
    end
  end,
})

return skel
